package com.yeban.javase.day02.test02;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/10/10
 */

/**
 * 2.
 * 1、创建GrandFather类，其中包括
 * a)属性：姓名（name），年龄（age）
 * b)方法getGrandFather()：显示爷爷的信息
 * c)构造方法：给爷爷的姓名，年龄赋值
 * <p>
 * 2、创建Father类，继承Grandfather类
 * a)属性：除了继承爷爷的属性以外，还要增加自己的属性：“职业”(occupation)
 * b)构造方法：显式调用父类的构造方法，为Father类的姓名和年龄赋初始值。再为职业输入初始值。
 * c)方法getFather(): 显示父亲的相关信息
 * <p>
 * 3、创建ClassMain类，定义main()方法，构造GrandFather类的对象和Father类的对象，并分别显示详细信息
 */
public class GrandFather {

    private String name;
    private int age;


    public GrandFather() {
    }

    public GrandFather(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void getGrandFather() {
        System.out.println("爷爷的信息是：" + this);
    }

    /**
     * 获取
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     *
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     *
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    public String toString() {
        return "GrandFather{name = " + name + ", age = " + age + "}";
    }
}
/**
 * 2、创建Father类，继承Grandfather类
 * a)属性：除了继承爷爷的属性以外，还要增加自己的属性：“职业”(occupation)
 * b)构造方法：显式调用父类的构造方法，为Father类的姓名和年龄赋初始值。再为职业输入初始值。
 * c)方法getFather(): 显示父亲的相关信息
 * <p>
 * 3、创建ClassMain类，定义main()方法，构造GrandFather类的对象和Father类的对象，并分别显示详细信息
 */

class Father extends GrandFather{

    private String occuption;

    public Father() {

    }

    public Father(String name, int age, String occuption) {
        super(name, age);
        this.occuption = occuption;
    }

    public Father(String occuption) {
        this.occuption = occuption;
    }

    public void getFather() {
        System.out.println("父亲的信息：" + this);
    }

    /**
     * 获取
     * @return occuption
     */
    public String getOccuption() {
        return occuption;
    }

    /**
     * 设置
     * @param occuption
     */
    public void setOccuption(String occuption) {
        this.occuption = occuption;
    }

    public String toString() {
        return "Father{occuption = " + occuption + "}";
    }
}

class ClassMain{

    public static void main(String[] args) {
        GrandFather gf = new GrandFather("张三",59);
        Father f = new Father("张四",35,"程序员");

        gf.getGrandFather();
        f.getFather();
    }
}